//
//  HWGameLiveChatSystemCell.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/10/27.
//

import UIKit

class HWGameLiveChatSystemCell: UITableViewCell {
    
    var contentLabel:UILabel!
    
    class func cellWithTableView(tableView:UITableView) -> (HWGameLiveChatSystemCell) {
        let reUse:String = "HWGameLiveChatSystemCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWGameLiveChatSystemCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWGameLiveChatSystemCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        contentLabel = HWLabel.createLabel(title: "", color: "#999999", font: 12*widthScale)
        contentView.addSubview(contentLabel)
        let attriString = NSMutableAttributedString.init(string: "  系统消息：提倡传播正能量内容，严格抵制低俗色情，一经发现永久封号。")
        
        attriString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.colorWithHexString(hexString: "#8D9AB1"), range: NSMakeRange(0, 5))
        attriString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.colorWithHexString(hexString: "#999999"), range: NSMakeRange(5, attriString.length-5))
        
        let markattch = NSTextAttachment() //定义一个attachment
        markattch.image = UIImage(named: "horn")//初始化图片
        markattch.bounds = CGRect(x: 0, y: -2, width: 13, height: 11) //初始化图片的 bounds
        let markattchStr = NSAttributedString(attachment: markattch) // 将attachment  加入富文本中
        attriString.insert(markattchStr, at: 0)// 将markattchStr  加入原有文字的某个位置
        
        let style = NSMutableParagraphStyle()
        style.lineSpacing = 5
        style.lineBreakMode = NSLineBreakMode.byWordWrapping
        attriString.addAttribute(NSAttributedString.Key.paragraphStyle, value: style, range: NSMakeRange(0, attriString.length))
        
        contentLabel.attributedText = attriString
        
    }
    
    func initFrame() -> Void {
        
        contentLabel.snp.makeConstraints { make in
            make.left.equalTo(21*widthScale)
            make.top.equalTo(5*widthScale)
            make.bottom.equalTo(-5*widthScale)
            make.right.equalTo(-21*widthScale)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
extension HWGameLiveChatSystemCell {
    
}
